package offer_board.action;


import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 public class BoardFrontController extends HttpServlet implements Servlet {
	 
	 protected void doGet(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException {
		doProcess(request,response);
	}  	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
		throws ServletException, IOException {
		doProcess(request,response);
	}  
	
	 protected void doProcess(HttpServletRequest request, HttpServletResponse response) 
	 	throws ServletException, IOException {
		 String RequestURI=request.getRequestURI();
		 String contextPath=request.getContextPath();
		 String command=RequestURI.substring(contextPath.length());
		 
		 System.out.println("RequestURI==="+RequestURI);
		 System.out.println("contextPath==="+contextPath);
		 System.out.println("command==="+command);
		 ActionForward forward=null;
		 Action action=null;
		   
		 if(command.equals("/board/BoardWrite.of")){
			   forward=new ActionForward();
			   forward.setRedirect(false);
			   forward.setPath("../board/qna_board_write.jsp");
		}/*else if(command.equals("/board/BoardReplyAction.of")){
			   action = new BoardReplyView();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		}*/else if(command.equals("/web/admin/shop_offer/BoardDelete.of")){
			   forward=new ActionForward();
			   forward.setRedirect(false);
			   forward.setPath("./offer_delete.jsp");
			   
			}/*else if(command.equals("/board/BoardModify.of")){
			   action = new BoardModifyView();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
	 	}*/else if(command.equals("/web/admin/shop_offer/BoardAddAction.of")){
			System.out.println("apple");  
	 		action  = new BoardAddAction();
			   try {
				   forward=action.execute(request, response );
			   } catch (Exception e) {
				   e.printStackTrace();
			   }
		}/*else if(command.equals("/board/BoardReplyView.of")){
			   action = new BoardReplyAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		}*//*else if(command.equals("/board/BoardModifyAction.of")){
			   action = new BoardModifyAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }*/else if(command.equals("/web/admin/shop_offer/BoardDeleteAction.of")){
			   System.out.println("컨드롤 단은 탄다");
			   action = new BoardDeleteAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }else if(command.equals("/web/shop/shop_offer/BoardList.of")){
			   System.out.println("컨트롤단 타는가.?");
			   action = new BoardListAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }else if(command.equals("/web/admin/shop_offer/BoardList.of")){
			   action = new BoardListAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }else if(command.equals("/web/shop/shop_offer/BoardListOffice.of")){
			   System.out.println("office 타냐?");
			   action = new BoardListOfficeAction();
			   try{
				   System.out.println("try탐 forward 리턴되서 돌아옴");
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }
		   else if(command.equals("/web/admin/shop_offer/BoardListCasual.of")){
			   System.out.println("admin casual 타냐?");
			   action = new BoardListCasualAction();
			   try{
				   System.out.println("try탐 forward 리턴되서 돌아옴");
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }
		   else if(command.equals("/web/shop/shop_offer/BoardListCasual.of")){
			   System.out.println("casual 타냐?");
			   action = new BoardListCasualAction();
			   try{
				   System.out.println("try탐 forward 리턴되서 돌아옴");
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }
		   else if(command.equals("/web/shop/shop_offer/BoardDetailAction.of")){
			   action = new BoardDetailAction();
			   try{
				   forward=action.execute(request, response);
			   }catch(Exception e){
				   e.printStackTrace();
			   }
		   }
		   if(forward.isRedirect()){
			   response.sendRedirect(forward.getPath());
		   }else{
			   RequestDispatcher dispatcher=
				   request.getRequestDispatcher(forward.getPath());
			   dispatcher.forward(request, response);
		   }
	 }
}